package com.hrt.manage.stock.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hrt.base.BaseController;
import com.hrt.bean.BackGoods;
import com.hrt.bean.GiftDetail;
import com.hrt.bean.GiftInfor;
import com.hrt.bean.ProductDetails;
import com.hrt.bean.ResourceType;
import com.hrt.bean.SnCodeSequence;
import com.hrt.bean.StockDetail;
import com.hrt.bean.Stocks;
import com.hrt.manage.product.service.GiftDetailService;
import com.hrt.manage.product.service.GiftInforService;
import com.hrt.manage.product.service.ProDetailsService;
import com.hrt.manage.product.service.ProInforService;
import com.hrt.manage.sncode.service.SNCodeService;
import com.hrt.manage.stock.service.StockDetailService;
import com.hrt.manage.stock.service.StocksService;
import com.hrt.vo.StockDetailVO;

@Controller
@RequestMapping("manage/stocksDetail")
public class StockDetailController extends BaseController<StockDetailVO> {

	@Autowired
	private StocksService stocksService;

	@Autowired
	private SNCodeService snCodeService;

	@Autowired
	private StockDetailService stocksDetailService;
	
	@Autowired
	private ProInforService proInforService;

	@Autowired
	private ProDetailsService proInforDetailService;

	@Autowired
	private GiftInforService giftInforService;

	@Autowired
	private GiftDetailService giftInforDetailService;
	
	
	

	@RequestMapping(value = "/queryDetailByPage")
	@ResponseBody
	public Map queryDetailByPage(
			@RequestParam(value = "id", required = true) Long stockId,
			@RequestParam(value = "pageIndex", required = false) Integer pageIndex,
			@RequestParam(value = "pageSize", required = false) Integer pageSize) {
		Map result = new HashMap();
		if (pageSize == null || "".equals(pageSize)) {
			pageSize = 5;
		}
		if (pageIndex == null || "".equals(pageIndex)) {
			pageIndex = 1;
		}
		setPageIndex(pageIndex);

		setPageSize(pageSize);
		List<StockDetailVO> resultList = new ArrayList<StockDetailVO>();

		resultList = stocksDetailService.getDetailByStockId(stockId, pageIndex,
				pageSize);
		this.setTotalCount(new Long(resultList.size()));
		this.setList(resultList);
		this.setPageCount(this.computePageCount(this.getTotalCount(),
				this.getPageSize()));
		page = this.getPage();
		result.put("pageResult", page);
		result.put("pageIndex", pageIndex);
		result.put("pageSize", getPageSize());
		result.put("totalCount", getTotalCount());
		return result;

	}

	@RequestMapping(value = "/queryStockDetailByCode")
	@ResponseBody
	public Map queryStockDetailByCode(
			@RequestParam(value = "snCode", required = true) String snCode,
			@RequestParam(value = "reType", required = true) Integer reType,
			HttpServletRequest request, HttpServletResponse response) {
		
		Map map = new HashMap();
		if (snCode != null && !"".equals(snCode)) {
			SnCodeSequence scs =snCodeService.getSnCodeByCode(snCode,reType);//加载条形码实体
			StockDetail sd = null;
			if(scs!=null){
			Long stockDetailId=scs.getStkDeId();
			
			if(stockDetailId!=null){
				StockDetailVO vo =  stocksDetailService.getDetailById(stockDetailId);//加载出库详情实体
				vo.setSnCode(scs.getSnCode());
				map=transBean2Map(vo);
				return map;
			}
			}
	
			
		

			
		}
		return null;
		

	}

}
